package structure;


public class ArrayStack {

    private int[] arr;
    private int top;

    public ArrayStack(int size) {
        arr = new int[size];
        top = -1;
    }

    // 入栈
    public void push(int value) {
        if (top == arr.length - 1){
            throw new RuntimeException("栈已满,无法入栈");
        }
        arr[++top] = value;
    }

    // 出栈
    public int pop() {
        if (top == -1){
            throw new RuntimeException("栈已空,无法出栈");
        }
        return arr[top--];
    }

}
